<template>
    <div>
        <el-form ref="form" :model="form" label-width="80px">

            <el-button type="primary">删除选中</el-button>
            <el-form-item>
                <el-select v-model="form.region" placeholder="地址" @change="diqu">
                    <el-option label="广东省" value="广东省"></el-option>
                    <el-option label="湖南省" value="湖南省"></el-option>
                    <el-option label="福建省" value="福建省"></el-option>
                </el-select>
            </el-form-item>
            <el-input v-model="form.name" style="width: 200px; margin-left: 20px;" placeholder="用户名" @blur="search_name"></el-input>
        </el-form>

        <el-table :data="tableData" border style="width: 100%">
            <el-table-column fixed prop="date"  type="selection" width="150">
            </el-table-column>
            <el-table-column fixed prop="id" label="id">
            </el-table-column>
            <el-table-column prop="name" label="用户名" >
            </el-table-column>
            <el-table-column prop="money" label="账户余额" >
            </el-table-column>
            <el-table-column prop="thumb" label="头像(查看大图)" >
                <template slot-scope="scope">
                     <el-image 
    style="width: 100px; height: 100px"
    :src="scope.row.thumb" 
    :preview-src-list="[scope.row.thumb]">
  </el-image>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="地址" >
            </el-table-column>
            <el-table-column prop="state" label="状态" >
                <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.state=='成功'">{{scope.row.state}}</el-tag>
                        <el-tag type="danger" v-if="scope.row.state=='失败'">{{scope.row.state}}</el-tag>
                        

                </template>
            </el-table-column>
            <el-table-column prop="date" label="注册时间" >
            </el-table-column>
            <el-table-column fixed="right" label="操作" >
                <template slot-scope="scope">
                    <el-button @click="sc(scope.row)" type="text" size="small">删除</el-button>
                    <el-button type="text" size="small"  @click="bj(scope.row)">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 弹出框编辑 -->
        <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
  <el-form :model="form1">

    <el-form-item label="用户名" :label-width="formLabelWidth">
      <el-input v-model="form1.name" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="地址" :label-width="formLabelWidth">
      <el-input v-model="form1.word" autocomplete="off"></el-input>
    </el-form-item>
   
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="qdbj">确 定</el-button>
  </div>
</el-dialog>
     <div class="foot">
        <input type="text" v-model="ye" @keyup.enter="key" style="width: 40px; border: 1px solid #ccc;"/>
        <ul>
            <li v-for="item,index in page" :key="index" @click="ma(item)">{{item}}</li>
        </ul>
    </div>
    </div>
</template>
<script>
import axios from 'axios'
export default {
    data() {
        return {
             form1: {
          name: '',
         word:'',
         id:0,
        },
        formLabelWidth: '120px',
            dialogFormVisible:false,
            list:[],
            tableData:[],
            page:[],
            ye:'',
            form: {
                name: '',
                region: ''
            }
        }
    },
    mounted() {
        this.xr()
    },
    methods: {
        //用户名搜索
        search_name(){
            let ass=this.list.filter(item=>{
               return item.name.includes(this.form.name)
            })
            this.tableData=ass
        },  
        //地区搜索
        diqu(){
            let asa=this.list.filter(item=>{
                return item.address.includes(this.form.region)
            })
            this.tableData=asa
            console.log(asa);
        },
        //确定编辑
        qdbj(){
            for (let i = 0; i < this.tableData.length; i++) {
                if(this.tableData[i].id==this.form1.id){
                    this.tableData[i].name=this.form1.name
                    this.tableData[i].address=this.form1.word
                    this.dialogFormVisible=false

                }
            }
        },
        //弹出编辑框
        bj(row){
            this.dialogFormVisible=true
            console.log(row);
            this.form1.name=row.name
            this.form1.word=row.address
            this.form1.id=row.id
        },
        //删除
        sc(row){
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          for (let i = 0; i < this.tableData.length; i++) {
                        if(this.tableData[i].id==row.id){
                            this.tableData.splice(i,1)
                             this.$message({
            type: 'success',
            message: '删除成功!'
          });
                        }                
            }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
            
           
        },
         //渲染
        xr(){
            axios.get('/params/table').then(res=>{
                this.list=res.data.data.list
                console.log(res);
                this.tableData=res.data.data.list
            })
        },
         ma(item){
            let bb=this.list
            let tou=(item-1)*this.ye
            let wei=item*this.ye
            this.tableData=bb.slice(tou,wei)
        },
        key(){
            this.page=[]
            let aa=this.list
            let pg=Math.ceil(this.list.length/this.ye) 
            for (let i = 1; i <= pg; i++) {
                this.page.push(i)  
            }
              this.tableData=aa.slice(0,this.ye) 
          
        },
       
       
    },
}
</script>
<style scoped>
ul{
    display: flex;
    margin-left: 600px;
}
li{
    list-style: none;
    padding: 10px 10px;
    margin: 0 10px;
    border: 1px solid #ccc;

}
.el-form-item {
    display: inline-block;
}
.im{
    width: 60px;
    height: 60px;
}
</style>